package com.itheima.reggie.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.dto.OrdersDto;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@RequestMapping("/order")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;


    //用户下单 --当前用户已经完成登录了，可以从session或者basecontext工具类获取当前用户的id，所以用户id不用传递
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders) {
        log.info("订单数据：{}", orders);
        ordersService.submit(orders);
        return R.success("下单成功！");
    }


    //用户个人中心订单信息查看
    @GetMapping("/userPage")
    public R<Page> userPage(int page, int pageSize) {
        Page<OrdersDto> dtoPage = ordersService.userPage(page, pageSize);

        return R.success(dtoPage);
    }

    //订单明细查看
    @GetMapping("/page")
    public R<Page<OrdersDto>> empPage(int page, int pageSize, String number, String beginTime, String endTime) {

        Page<OrdersDto> empPage = ordersService.empPage(page, pageSize, number, beginTime, endTime);

        return R.success(empPage);
    }

}
